using System.Linq.Expressions;
using DictToObject.FieldExpectations;
using DictToObject.Helpers;

namespace DictToObject.Factories
{
    public class FieldExpectationFactory : IFieldExpectationFactory
    {
        private readonly IFieldLikeMemberFactory fieldLikeMemberFactory;

        public FieldExpectationFactory(IFieldLikeMemberFactory fieldLikeMemberFactory)
        {
            this.fieldLikeMemberFactory = fieldLikeMemberFactory;
        }

        public IRequiredFieldExpectation GetRequiredFieldExpectation(string key, MemberExpression memberExpression)
        {
            IFieldLikeMember member = fieldLikeMemberFactory.Create(memberExpression.Member);
            return new RequiredFieldExpectation(key, member);
        }

        public IOptionalFieldExpectation GetOptionalFieldExpectation(string key, MemberExpression memberExpression, object defaultValue)
        {
            IFieldLikeMember member = fieldLikeMemberFactory.Create(memberExpression.Member);
            return new OptionalFieldExpectation(key, member, defaultValue);
        }
    }
}